﻿Imports System.Data.OleDb

Public MustInherit Class TagGateway
    Inherits DataGateway

    Protected Overrides ReadOnly Property FindAllQuery As String
        Get
            Return "SELECT * FROM Tag"
        End Get
    End Property

    Protected Overrides ReadOnly Property DeleteQuery As String
        Get
            Return "DELETE FROM Tag"
        End Get
    End Property

    Public Function Insert(ByVal title As String) As ULong
        Dim newID As ULong
        Dim sqlQuery As String = "INSERT INTO Tag (Title) VALUES (@Title)"
        Using connection As New OleDbConnection(ConnectionString)
            Using command As New OleDbCommand(sqlQuery, connection)
                command.CommandType = CommandType.Text
                command.Parameters.AddWithValue("@Title", title)
                connection.Open()
                command.ExecuteNonQuery()
                newID = GetLastInsertID(command)
            End Using
        End Using

        Return newID
    End Function

End Class
